package com.ruoyi.eqmonitor.smdtv.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.eqmonitor.dtos.CockpitRiverwayAlarmDto;
import com.ruoyi.eqmonitor.vo.CockpitVo;
import com.ruoyi.eqmonitor.dtos.OptDeviceAlarmDto;
import com.ruoyi.eqmonitor.service.IOptPatrolEventService;
import com.ruoyi.eqmonitor.smdtv.domain.SmdtvOverflowWell;
import com.ruoyi.eqmonitor.smdtv.mapper.SmdtvOverflowWellMapper;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtvOverflowWellService;
import com.ruoyi.eqmonitor.utils.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 溢流井整治情况Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-15
 */
@Service
public class SmdtvOverflowWellServiceImpl extends ServiceImpl<SmdtvOverflowWellMapper, SmdtvOverflowWell> implements ISmdtvOverflowWellService {
    
    @Autowired
    private SmdtvOverflowWellMapper smdtvOverflowWellMapper;

    @Autowired
    private IOptPatrolEventService optPatrolEventService;

    @Override
    public SmdtvOverflowWell selectSmdtvOverflowWellById(Long id){
        return smdtvOverflowWellMapper.selectSmdtvOverflowWellById(id);
    }
      
    @Override
    public List<SmdtvOverflowWell> selectSmdtvOverflowWellList(SmdtvOverflowWell smdtvOverflowWell){
        return smdtvOverflowWellMapper.selectSmdtvOverflowWellList(smdtvOverflowWell);
    }

    @Override
    public List<OptDeviceAlarmDto> cockpitRiverwayAlarm(CockpitRiverwayAlarmDto dto) {
        List<OptDeviceAlarmDto> list = new ArrayList<>();
        if (dto.getAlarmCode() != 1){
            if (dto.getAlarmCode() != 1){
                List<CockpitVo> vos = smdtvOverflowWellMapper.cockpitRiverwayAlarm(dto);
                list = optPatrolEventService.reCockpitData(vos, "溢流井");
            }
        }
        return list;
    }

    @Override
    public boolean updateConfirmAlarmToInDisposal(String alarmId,Integer state) {
        if (ObjectUtil.isNull(alarmId)) return false;
        LambdaUpdateWrapper<SmdtvOverflowWell> wrapper = Wrappers.lambdaUpdate();
        if (state == 1){
            wrapper.set(SmdtvOverflowWell::getConfirmAlarm, Constant.ConfirmAlarmType.IN_DISPOSAL.getValue());
        }else {
            wrapper.set(SmdtvOverflowWell::getConfirmAlarm, Constant.ConfirmAlarmType.CLEARED.getValue());
        }
        wrapper.eq(SmdtvOverflowWell::getId, alarmId);
        return update(wrapper);
    }
}
